import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-07-21
 * Time: 16:34
 */
public class Test {
    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7};
        rotate(nums, 3);
        System.out.println(Arrays.toString(nums));
    }


    public static void rotate(int[] nums, int k) {
        int len = nums.length;
        if(len == 1) {
            return;
        }
        k = k % len;
        int[] newNums = new int[k];
        int j = 0;
        for(int i = len-k; i < len; i++) {
            newNums[j++] = nums[i];
        }
        for(int i = len-k-1; i >= 0; i--){
            nums[i+k] = nums[i];
        }
        for(int i = 0; i < k; i++) {
            nums[i] = newNums[i];
        }
    }
}
